﻿<?php
$edit_url	=	"?act=list_cat";
if ($del_id) {
	acp_check_permission('del_cat');
	if ($_POST['submit']) {
		$mysql->query("DELETE FROM ".$tb_prefix."cat WHERE cat_id = '".$del_id."'");
		echo "Đã xóa xong <meta http-equiv='refresh' content='0;url=".$edit_url."'>";
		exit();
	}
	?><table align=center><form method="post">Bạn có muốn xóa không ??????<br><center><input value="Có" name=submit type=submit class=submit></center></form></table><?
}
if($mode == 'edit') {
acp_check_permission('edit_cat');
	if(is_numeric($id)) {
		$sql	=	"SELECT * FROM ".$tb_prefix."cat WHERE cat_id = $id";
		$query	=	$mysql->query($sql);
		if($mysql->num_rows($query)) {
			$row =	$mysql->fetch_array($query);
			$cat_NAME	=	$row['cat_name'];
			$cat_ORDER	=	$row['cat_order'];
			$cat_SUB	=	$row['sub_id'];
			$action		=	"?act=cat&mode=edit&id=$id";
			if(isset($_POST['submit'])) {
				$name	=	$_POST['name'];
				$order	=	$_POST['order'];
				$sub	=	$_POST['sub'];
				$mysql->query("UPDATE ".$tb_prefix."cat SET
					cat_name		=  	'".$name."',
					cat_order 		= 	'".$order."',
					sub_id			=	'".$sub."' WHERE cat_id = '".$id."'");
				echo "<script language='JavaScript'>{ window.parent.location='?act=cat&mode=edit&id=$id' }</script>";
			}
		}
	}
	if(!$mysql->num_rows($query)) {
		die("Thể loại này chua có trong data");
	}
include("templates/cat.html");
}
if($mode == 'add') {
acp_check_permission('add_cat');
	if(isset($_POST['submit'])) {
		$name	=	$_POST['name'];
		$order	=	$_POST['order'];
		$sub	=	$_POST['sub'];
		$mysql->query("INSERT INTO ".$tb_prefix."cat (cat_name,cat_order,sub_id) 
					VALUES ('".$name."','".$order."','".$sub."')");
		echo "<script language='JavaScript'>{ window.parent.location='?act=list_cat' }</script>";
	}
include("templates/cat.html");
}
		
?>